
CMAKE_MINIMUM_REQUIRED(VERSION 3.13...3.20)

project(histreamer)

if (MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
else ()
    # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif ()

set(TOP_DIR ${CMAKE_SOURCE_DIR})
set(DEV_TOP_DIR ${TOP_DIR})
set(curl_ca_path ${TOP_DIR}/3rdparty/curl/)
add_definitions(-DCA_DIR="${curl_ca_path}")

# uncomment this line to enable Video
set(VIDEO_ENABLE TRUE)

# uncomment this line to enable Recorder
set(RECORDER_ENABLE TRUE)
add_definitions(-DSUPPORT_PLAYER) # add -DSUPPORT_PLAYER to enable player
add_definitions(-DSUPPORT_RECORDER) # add -DSUPPORT_RECORDER to enable recorder

# uncomment this line to enable 3D audio
# set(AVS3DA_ENABLE TRUE)

if (VIDEO_ENABLE)
    add_definitions(-DVIDEO_SUPPORT) # add -DVIDEO_SUPPORT to enable video play
endif ()

if (RECORDER_ENABLE)
    add_definitions(-DRECORDER_SUPPORT) # add -DRECORDER_SUPPORT to enable recorder
endif ()

if (AVS3DA_ENABLE)
    add_definitions(-DAVS3DA_SUPPORT) # add -DAVS3DA_SUPPORT to enable 3D audio play
endif ()

#set(CMAKE_VERBOSE_MAKEFILE ON)

IF (WIN32)
    include_directories(
            ${TOP_DIR}/adapter/windows
    )
ELSEIF (ANDROID)
ELSE ()
    SET(LINUX_DEMO TRUE)
    include_directories(
            ${TOP_DIR}/adapter/linux
    )
ENDIF ()

set(THIRD_PARTY_DIR ${TOP_DIR}/3rdparty)
set(GTEST_ROOT_DIR ${TOP_DIR}/3rdparty/gtest)
set(MOCKCPP_DIR ${TOP_DIR}/3rdparty/mockcpp)
set(THIRD_PARTY_OH_DIR ${TOP_DIR}/3rdparty/ohos)
set(HISTREAMER_PLUGINS_DIR ${TOP_DIR}/histreamer_plugins)

include_directories(
        ${TOP_DIR}/3rdparty/ffmpeg/include
        ${TOP_DIR}/3rdparty/SDL2.0/include
        ${TOP_DIR}/3rdparty/minimp3
        ${TOP_DIR}/3rdparty/curl/include
        ${TOP_DIR}/plugins
        ${THIRD_PARTY_OH_DIR}/third_party/bounds_checking_function/include
)

if (WIN32)
    set(ffmpeg_lib_path ${TOP_DIR}/3rdparty/ffmpeg/windows/lib)
    set(sdl_lib_path ${TOP_DIR}/3rdparty/SDL2.0/windows/lib/x64)
    add_definitions(-DUSING_CLOCK_REALTIME -DWIN32)
endif ()

unset(OHOS_LITE CACHE)
option(OHOS_LITE "default player mode" OFF)
if (OHOS_LITE)
    add_definitions(-DOHOS_LITE)
endif ()
message(STATUS "OHOS_LITE is ${OHOS_LITE}")

if (OHOS_LITE)
    set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
    # player lite
    include_directories(
        ${THIRD_PARTY_OH_DIR}/foundation/multimedia/media_lite/interfaces/innerkits
        ${THIRD_PARTY_OH_DIR}/foundation/multimedia/media_lite/interfaces/kits/player_lite
        ${THIRD_PARTY_OH_DIR}/foundation/multimedia/utils/lite/interfaces/kits
        ${THIRD_PARTY_OH_DIR}/foundation/graphic/surface/interfaces/kits
        ${THIRD_PARTY_OH_DIR}/foundation/graphic/utils/interfaces/kits
    )
    file(GLOB_RECURSE 3RDPARTY_SRCS
        ${THIRD_PARTY_OH_DIR}/foundation/multimedia/utils/lite/src/*.cpp
        #${THIRD_PARTY_OH_DIR}/foundation/graphic/surface/frameworks/*.cpp
        ${THIRD_PARTY_OH_DIR}/third_party/bounds_checking_function/src/*.c
    )
else ()
    set(CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}")
    # player standard
    include_directories(
            ${THIRD_PARTY_OH_DIR}/foundation/multimedia/media_standard/services/services/engine_intf
            ${THIRD_PARTY_OH_DIR}/foundation/multimedia/media_standard/interfaces/innerkits/native/media/include
            ${THIRD_PARTY_OH_DIR}/utils/native/base/include
            ${THIRD_PARTY_OH_DIR}/foundation/graphic/standard/interfaces/innerkits/surface
            ${THIRD_PARTY_OH_DIR}/foundation/graphic/standard/interfaces/innerkits/common
            ${THIRD_PARTY_OH_DIR}/foundation/graphic/standard/utils/sync_fence/export
            ${THIRD_PARTY_OH_DIR}/foundation/communication/ipc/interfaces/innerkits/ipc_core/include
            ${THIRD_PARTY_OH_DIR}/foundation/graphic/standard/utils/buffer_handle/export
            ${THIRD_PARTY_OH_DIR}/drivers/hdf_core/adapter/uhdf2/osal/include
            ${THIRD_PARTY_OH_DIR}/drivers/hdf_core/framework/include/utils
            ${THIRD_PARTY_OH_DIR}/drivers/peripheral/base
            ${THIRD_PARTY_OH_DIR}/drivers/peripheral/codec/hal/include
            ${THIRD_PARTY_OH_DIR}/drivers/peripheral/codec/interfaces/include
            ${THIRD_PARTY_OH_DIR}/drivers/peripheral/display/interfaces/include
            ${THIRD_PARTY_OH_DIR}/foundation/multimedia/image_standard/interfaces/innerkits/include
            ${THIRD_PARTY_OH_DIR}/foundation/multimedia/audio_standard/interfaces/inner_api/native/audiocapturer/include
            ${THIRD_PARTY_OH_DIR}/foundation/multimedia/audio_standard/frameworks/innerkitsimpl/audiocapturer/src
            ${THIRD_PARTY_OH_DIR}/foundation/multimedia/audio_standard/interfaces/inner_api/native/audiocommon/include
            ${THIRD_PARTY_OH_DIR}/foundation/multimedia/audio_standard/interfaces/inner_api/native/audiorenderer/include
            ${THIRD_PARTY_OH_DIR}/foundation/graphic/standard/interfaces/innerkits
            ${THIRD_PARTY_OH_DIR}/startup/syspara_lite/interfaces/innerkits/native/syspara/include
            ${THIRD_PARTY_OH_DIR}/base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter
            ${THIRD_PARTY_OH_DIR}/third_party/openmax/api/1.1.2
    )
    file(GLOB_RECURSE 3RDPARTY_SRCS
            ${THIRD_PARTY_OH_DIR}/drivers/peripheral/codec/interfaces/src/*.cpp
            ${THIRD_PARTY_OH_DIR}/foundation/multimedia/media_standard/services/utils/*.cpp
            ${THIRD_PARTY_OH_DIR}/foundation/graphic/standard/interfaces/innerkits/surface/*.cpp
            ${THIRD_PARTY_OH_DIR}/foundation/graphic/standard/utils/sync_fence/src/*.cpp
            ${THIRD_PARTY_OH_DIR}/foundation/multimedia/audio_standard/frameworks/innerkitsimpl/audiocapturer/src/*.cpp
            ${THIRD_PARTY_OH_DIR}/foundation/multimedia/audio_standard/frameworks/innerkitsimpl/audiorenderer/src/*.cpp
            ${THIRD_PARTY_OH_DIR}/utils/native/base/src/*.cpp
            ${THIRD_PARTY_OH_DIR}/startup/syspara_lite/interfaces/innerkits/native/syspara/src/*.c
            ${THIRD_PARTY_OH_DIR}/third_party/bounds_checking_function/src/*.c
            ${THIRD_PARTY_OH_DIR}/base/hiviewdfx/hitrace/interfaces/native/innerkits/src/*.cpp
    )
endif()

set(GTEST_LIB gtest gtest_main)

set(PLAYER_INTERFACE_DIR ${TOP_DIR}/histreamer/interface)

if (CMAKE_HOST_WIN32)
    SET(3RDPARTY_SRCS ${3RDPARTY_SRCS} ${TOP_DIR}/adapter/windows/log_adapter.cpp)
endif()

include(histreamer.cmake)

if (CMAKE_HOST_UNIX)
    add_subdirectory(demo/linux)
elseif (CMAKE_HOST_WIN32)
    add_subdirectory(demo/windows)
    add_subdirectory(demo/system_tests)
    add_subdirectory(3rdparty/debug/crashdump/cpp_plain)
endif ()
